//定义一个map，关键字是家庭的姓，值是一个vector，保存家中孩子（们）的名。
//编写代码，实现添加新的家庭以及向已有家庭中添加新的孩子。
//添加操作暂未加入，对文件操作还有疑问
#include<iostream>
#include<vector>
#include<list>
#include<algorithm>
#include<iterator>
#include<fstream>
#include<string>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int main()
{
	map<string, vector<string>>name;
	string word,words;
	string first, second;
	int index = 0;
	ifstream in("text.txt");
	if (!in)
	{
		cout << "error to open file" << endl;
	}
	while (getline(in,word)){
		istringstream is(word);
		while (is >> words) {
			if (index == 0)
			{
				first = words;
				++index;
			}
			else {
				second = words;
				name[first].push_back(second);
			}
		}
		index = 0;

	}
	in.close();
	ofstream op("text.txt",ios::app);
	if (!op)
	{
		cout << "error to open file" << endl;
	}
	op.close();
	for (auto k : name)
	{
		cout << k.first << "家的孩子";
		for (auto j : k.second)
		{
			cout << k.first<<j << " ";
		}
		cout << endl;
	}

}